<?php

namespace App\Http\Requests;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait StaffRequest 
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'name' => 'required|string|max:255',
            'name_en' => 'required|string|max:255',
            'role_id' => 'required|integer',
            'dept_id' => 'required|integer',
            'gender' => 'required|integer|in:1,2,3',
            'status' => 'required|integer|in:1,2',
        ], [
            'name.required' => '请填写员工姓名',
            'name.max' => '员工姓名长度不能超过255个字符',
            'name_en.required' => '请填写英文名称',
            'name_en.max' => '英文名称长度不能超过255个字符',
            'role_id.required' => '请选择职位角色',
            'dept_id.required' => '请选择所属部门',
            'gender.required' => '请选择性别',
            'gender.in' => '性别值无效',
            'status.required' => '请选择在职状态',
            'status.in' => '在职状态错误',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
